﻿@using ZBJF.Warranty.Common.Enums.InsuranceWarranty
@using ZBJF.Warranty.WebProvider
@using ZBJF.Warranty.Common.Enums
@{
    ViewBag.Title = "Index";
}
@section Header{
    @Scripts.Render("~/bundles/datatable")
    @Styles.Render("~/Content/datatable")
}
@model ZBJF.Warranty.Model.InsuranceWarrantyRecord
<ul class="nav nav-tabs">
    <li class="active">
        <a href="/InsuranceWarrantyRecord/Index?FinanceType=@Request["FinanceType"]">
            @(Convert.ToInt32(Request["FinanceType"]) == 1 ? "收款列表" : "付款列表")
        </a>
    </li>
</ul>
<form id="searchForm" class="breadcrumb form-search">
    <table style="text-align: right;">
        <tr>
            <td>被保险人姓名:</td>
            <td>@Html.TextBox("UserName", "", new {maxlength = 20, @class = "input-small"})</td>
            <td>被保险人电话:</td>
            <td>@Html.TextBox("UserPhone", "", new {maxlength = 20, @class = "input-small"})</td>
            <td class="showth2 center">被保险人证件号码:</td>
            <td class="showth2 center">@Html.TextBox("CertificateNO", "", new { maxlength = 20, @class = "input-small" })</td>
            <td>报案单号:</td>
            <td>@Html.TextBoxFor(m => m.WarrantyRecordNo, new {maxlength = 20, @class = "input-small"})</td>
            <td class="showth center">报案人姓名:</td>
            <td class="showth center">@Html.TextBox("Reporter", "", new { maxlength = 20, @class = "input-small" })</td>
            <td class="showth2 center">销售商户:</td>
            <td class="showth2 center">@Html.TextBox("SaleVendorName", "", new {maxlength = 20, @class = "input-small"})</td>
            <td class="showth center">报案人电话:</td>
            <td class="showth center">@Html.TextBox("ReporterPhone", "", new { maxlength = 20, @class = "input-small" })</td>
        </tr>
        <tr class="showth2 center">
            <td>第三方承保公司:</td>
            <td>@Html.TextBox("InsuranceCompany", "", new { maxlength = 20, @class = "input-small" })</td>
            <td>承保公司分公司:</td>
            <td>@Html.TextBox("InsuranceCompanyBranch", "", new { maxlength = 20, @class = "input-small" })</td>
            <td>保险产品类型:</td>
            <td>
                <select id="InsuranceCategoryName" name="InsuranceCategoryName" style="width: 110px;">
                    <option value="">请选择</option>
                    <option value="碎屏险">碎屏险</option>
                </select>
            </td>
            <td>保险产品名称:</td>  
            <td>@Html.TextBox("ProductName", "", new { maxlength = 20, @class = "input-small" })</td>
            <td>第三方保单号:</td>
            <td>@Html.TextBox("ThirdOrderNO", "", new { maxlength = 20, @class = "input-small" })</td>
        </tr>
        <tr>
            <td class="showth center">保险产品类型:</td>
            <td class="showth center">
                <select id="InsuranceCategoryName1" name="InsuranceCategoryName" style="width: 110px;">
                    <option value="">请选择</option>
                    <option value="碎屏险">碎屏险</option>
                </select>
            </td>
            <td class="showth center">保险产品名称:</td>
            <td class="showth center">@Html.TextBox("ProductName1", "", new {maxlength = 20, @class = "input-small"})</td>
            <td class="showth center">服务商名称:</td>
            <td class="showth center">@Html.TextBox("BankAccountName", "", new { maxlength = 20, @class = "input-small" })</td>
            @{
                var insuranceWarrantyStatusName = Convert.ToInt32(Request["FinanceType"]) == 1 ? "收款状态" : "付款状态";
                var selectList = Convert.ToInt32(Request["FinanceType"]) == 1 ? ConvertToSelector.Instance.EnumTypeConvertToSelectList(typeof (InsuranceWarrantyReceiptStatus)) : ConvertToSelector.Instance.EnumTypeConvertToSelectList(typeof (InsuranceWarrantyPaymentStatus));
            }
            <td>@(insuranceWarrantyStatusName):</td>
            <td>@Html.DropDownListFor(m => m.ReceiptStatus, selectList, new {style = "width:112px;"})</td>
            <td colspan="3">
                <input id="btnSubmit" class="btn btn-primary  Search-R margin-l-10" type="button" value="查询 " onclick="search();">
                @{ var value = Convert.ToInt32(Request["FinanceType"]) == 1 ? "导出收款清单" : "导出付款清单";}
                <input id="btnExport" class="btn btn-success Search-R margin-l-10" type="button" value="@value" onclick="ExportData(@(Request["FinanceType"]))">
                <input id="btnImportExport" class="btn btn-success Search-R margin-l-10" type="button" value="导入对账清单" onclick="ExporOpen(@(Request["FinanceType"]))">
            </td>
        </tr>
    </table>
</form>
<div class="table-responsive dataTables_wrapper">
    <table id="insuranceWarrantyRecordList" class="table table-striped table-bordered table-hover" width="100%">
        <thead>
            <tr>
                <th width="20">序号</th>
                <th >报案单号</th>
                <th  class="showth center">报案人姓名</th>
                <th  class="showth center">报案人电话</th>
                <th >被保险人</th>
                <th >被保险人电话</th>
                <th >被保险人证件号码</th>
                <th >保险产品类别</th>
                <th >保险产品名称</th>
                <th  class="showth2 center">第三方保单号</th>
                <th  class="showth2 center">第三方承保公司</th>
                <th  class="showth2 center">承保公司分公司</th>
                <th  class="showth2 center">销售商户</th>
                <th class="showth center">服务商</th>
                <th class="center" width="100">关单时间</th>
                <th class="showth2 center" width="100">应收金额</th>
                <th class="showth2 center" width="100">收款状态</th>
                <th class="showth2 center" width="100">收款时间</th>
                <th class="showth center" width="100">应付金额</th>
                <th class="showth center" width="100">付款状态</th>
                <th  class="showth center" width="100">付款时间</th>
            </tr>
        </thead>
    </table>
</div>
@section scripts{
    <script type="text/javascript">
        window.onload = function() {
            search();
            if (Number(@Request["FinanceType"]) == 1) {
                $(".showth").css("display", "none");
            } else {
                $(".showth2").css("display", "none");
            }
        }
        function reset() {
            document.getElementById("excelForm").reset();
        }

        var isSearch = false;
        var zipFileName = '';
        $(function() {
            var objTable =Number(@Request["FinanceType"])==1?
                    $("#insuranceWarrantyRecordList")
                .dataTable({
                    fnDrawCallback: function() {
                        ControlPermissionOperate();
                    },
                    "aaSorting": [[9, "desc"]],
                    "sAjaxSource": "/InsuranceWarrantyRecord/Index?FinanceType=" + @Request["FinanceType"],
                    aoColumns:[
                        {
                            "mData": null,
                            "bSortable": false,
                            "fnRender": function(nRow) {
                                return nRow.iDataRow + 1;
                            }
                        },
                        { "mData": "WarrantyRecordNo" },
                        { "mData": "UserName" },
                        { "mData": "UserPhone" },
                        { "mData": "CertificateNO" },
                        { "mData": "InsuranceCategoryName" },
                        { "mData": "ProductName" },
                         { "mData": "ThirdOrderNO" },
                         { "mData": "InsuranceCompany"},
                         { "mData":"InsuranceCompanyBranch"},
                        { "mData": "SaleVendorName"},
                        { "mData": "LastModifyTime" },
                        { "mData":"ReceivableAmount"},
                        { "mData":"ReceiptStatusDesc"},
                        { "mData":"ReceiptTime"}
                    ] 
                }):$("#insuranceWarrantyRecordList")
                .dataTable({
                    fnDrawCallback: function() {
                        ControlPermissionOperate();
                    },
                    "aaSorting": [[9, "desc"]],
                    "sAjaxSource": "/InsuranceWarrantyRecord/Index?FinanceType=" + @Request["FinanceType"],
                    aoColumns: [
                        {
                            "mData": null,
                            "bSortable": false,
                            "fnRender": function(nRow) {
                                return nRow.iDataRow + 1;
                            }
                        },
                        { "mData": "WarrantyRecordNo" },
                         { "mData": "Reporter" },
                        { "mData": "ReporterPhone" },
                        { "mData": "UserName" },
                        { "mData": "UserPhone" },
                        { "mData": "CertificateNO" },
                        { "mData": "InsuranceCategoryName" },
                        { "mData": "ProductName" },     
                        { "mData": "ServiceProviderName" }, 
                        { "mData": "LastModifyTime" },
                        { "mData": "PayableAmount"},
                        { "mData": "PaymentStatusDesc"},
                        { "mData": "PaymentTime"}
                    ]
                });
        });

        //查询
        function search() {
            queryParamList.InsuranceCompany = $("#InsuranceCompany").val().trim();
            queryParamList.ThirdOrderNO = $("#ThirdOrderNO").val().trim();
            queryParamList.InsuranceCompanyBranch = $("#InsuranceCompanyBranch").val().trim();
            queryParamList.InsuranceCategoryName =@(Convert.ToInt32(Request["FinanceType"]))==1?$("#InsuranceCategoryName").val().trim():$("#InsuranceCategoryName1").val().trim();
            queryParamList.ProductName =@(Convert.ToInt32(Request["FinanceType"]))==1?$("#ProductName").val().trim():$("#ProductName1").val().trim();
            queryParamList.UserName = $("#UserName").val().trim();
            queryParamList.UserPhone = $("#UserPhone").val().trim();
            queryParamList.CertificateNO = $("#CertificateNO").val().trim();
            queryParamList.WarrantyRecordNo = $("#WarrantyRecordNo").val().trim();
            queryParamList.SaleVendorName = $("#SaleVendorName").val().trim();
            queryParamList.BankAccountName = $("#BankAccountName").val().trim();
            if (@(Convert.ToInt32(Request["FinanceType"])) == 1) {
                queryParamList.ReceiptStatus = $("#ReceiptStatus").val().trim();
            } else {
                queryParamList.PaymentStatus = $("#ReceiptStatus").val().trim();
            }
            $("#insuranceWarrantyRecordList").dataTable().fnDraw();
        }

        function ExporOpen(id) {
            var url = id == 1 ? '/InsuranceWarrantyRecord/ImportInsuranceWarrantyRecord' : '/InsuranceWarrantyRecord/ImportInsuranceWarrantyRecordPayment';
            debugger;
            layer.open({
                type: 2,
                title: '上传对账清单',
                shadeClose: true,
                shade: 0.8,
                area: ['600px', '60%'],
                content: url //iframe的url
            });
        }

        function ExportData(id) {
            /*导出数据*/
            if (!confirm("确定要导出Excel吗？")) return;
            search();
            queryParamList.FinanceType = id;
            if (id == 1) {
                window.location.href = '@Url.Action("ExportInsuranceWarrantyRecordDetails")?content=' + JSON.stringify(queryParamList);
            } else {
                window.location.href = '@Url.Action("ExportPaymentInsuranceWarrantyRecordDetails")?content=' + JSON.stringify(queryParamList);
            }
        }
    </script>
}